package com.microhifo.service;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import tool.MyApplicationContext;



import com.microhifo.mapper.*;
import com.microhifo.model.*;




/**
 * 单例模式 分销系统的user服务类，用于数据同步
 * 
 * @author chz
 * 
 */

public class UserService {
	// 单例模式 start
	private volatile static UserService instance = null;
	private ApplicationContext ac = null;
	private UserMapper userMapper;
	private UserService() {
//		this.ac = new ClassPathXmlApplicationContext("/config/spring-common-mysql.xml");
		this.ac = MyApplicationContext.mysql_ac;
		this.userMapper =  ac.getBean(UserMapper.class);
		
	}

	public static UserService getInstance() {
		if (instance == null) {
			synchronized (UserService.class) {// 1
				if (instance == null) {// 2
					instance = new UserService();// 3
				}
			}
		}
		return instance;
	}
	// 单例模式 end
	
//	test
	public static void main(String[] args){
		
		
	}

	public UserMapper getUserMapper() {
		return this.userMapper;
	}
	
}